package com.music.hbox.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.music.domain.Music;
import com.music.hbox.dao.FindDescMusicDao;


@Repository
public class FindDescMusicDaoImpl implements FindDescMusicDao{
	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public List<Music> findDescMusic() {
		String hql="from Music order by createdate desc";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		query.setFirstResult((int)(Math.random()*10));
		query.setMaxResults(12);
		List<Music> data = query.list();
		return data;
	}

}
